home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / GMSMTH01.ZIP / INCLUDE / SPRITE.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-08  |  7.3 KB  |  227 lines

  1. /*
  2.  
  3.     sprite.h
  4.  
  5.     Internet: alexad3@icebox.iceonline.com
  6.     Copyright 1995, April 13 by Bruce Miller, ALL rights reserved
  7.  
  8.     Created - 1995/4/13
  9.  
  10.     History:
  11.         New file
  12.  
  13.     Modified 21Apr95 by Bruce Miller:
  14.  
  15.      * Moved init_sprite_bank() into sprbank.c from sprite.c, removed
  16.        header from sprite.h, added to sprbank.h
  17.  
  18. */
  19.  
  20. #ifndef DEF_SPRITE
  21. #define DEF_SPRITE 1
  22.  
  23. #define sprite_header_included 1
  24.  
  25. // Misc. constants
  26. #define M13_HEADER_SIZE 4
  27. #define PROPORTIONAL 512
  28.  
  29. // clipping control constants
  30. #define X_CLIP 1
  31. #define Y_CLIP 2
  32. #define XY_CLIP 3
  33.  
  34. enum sprite_type
  35.      {
  36.      SPRITE_PBM,  // standard planed
  37.      SPRITE_PKB,  // RLE planed (packed)
  38.      SPRITE_M13,  // LINEAR, LBM usualy means a dpaint format file
  39.      SPRITE_CBM   // compiled
  40.      };
  41.  
  42. // this points to the actual bitmaps
  43. typedef struct
  44.      {
  45.      short num_bitmaps;         // number of bitmaps
  46.      short default_change_delay;// ticks between frames
  47.      short default_change_mode; // default method of changing bitmaps
  48.      short default_move_mode;   // default method of movement at limits
  49.  
  50.      BYTE far * far *bitmaps;     // array of pointers to bitmaps
  51.      BYTE far * far *clip_pbm_bitmaps; // array of pointers to .pbm bitmaps
  52.      }                                 // used for clipping .cbm, .pkb's
  53. sprite_header_t;
  54.  
  55. // structure containing extra information stored before each bitmap in file
  56. typedef struct
  57.      {
  58.      BYTE type;            // type of bitmap
  59.      short cx, cy;         // location of visual centre, relative to x,y
  60.      USHORT size;                  //  (size necessary to packedbitmaps)
  61.      short pixel_width, pixel_height;
  62.  
  63.      // Collision support, used for a smaller rectangle based on shape of
  64.      //  bitmap, all are offsets from x,y.
  65.      short collide_left, collide_right;
  66.      short collide_top,  collide_bottom;
  67.  
  68.    short x_offs1, y_offs1;   // offsets used to start bullets, missiles,
  69.    short x_offs2, y_offs2;   // attach objects, etc.
  70.    short x_offs3, y_offs3;
  71.    short x_offs4, y_offs4;
  72.      }
  73. bitmap_info_t;
  74.  
  75. /* -------------- instances ------------------------------------------ */
  76.  
  77. // structs etc for intances of a sprite
  78. enum modes
  79.      {
  80.      SPR_CHG_DEAD,      // don't display at all
  81.      SPR_CHG_STOP,      // don't animate, show curr_frame only
  82.      SPR_CHG_FORWARD,   // inc frame, goto 1st when hit end
  83.      SPR_CHG_BACKWARD,  // dec frame, goto last when hit end
  84.      SPR_CHG_PINGPONG,  // inc frame until end, then dec frame etc...
  85.      SPR_CHG_FORW_HOLD, // inc through set once, then stop
  86.      SPR_CHG_FORW_DIE   // inc through set once, then die
  87.      };
  88.  
  89. enum movement_modes
  90.      {
  91.      SPR_NO_LIMITS,              // default, take no action or clip at
  92.                                          //      limits if clipping = 1;
  93.      SPR_HOLD_AT_XLIMIT,         // hold at x limit only
  94.      SPR_HOLD_AT_YLIMIT,         // hold at y limit only
  95.      SPR_HOLD_AT_XYLIMIT,        // hold at both limits
  96.  
  97.      SPR_CLIP_DIE_AT_XYLIMIT,    // clip, then die when offscreen
  98.  
  99.      SPR_DIE_AT_XLIMIT,          // disappear, die at x limits only
  100.      SPR_DIE_AT_YLIMIT,
  101.      SPR_DIE_AT_XYLIMIT,
  102.  
  103.      SPR_BOUNCE_AT_XLIMIT,
  104.      SPR_BOUNCE_AT_YLIMIT,
  105.      SPR_BOUNCE_AT_XYLIMIT
  106.      };
  107.  
  108. // many of these can point to the same sp_header
  109. typedef struct
  110. {
  111. BYTE id;                   // unique id number
  112. USHORT attrib;             // attribute word - can be use for attribute bits
  113. sprite_header_t far *sp_header;// points to main sprite header
  114.  
  115. BYTE far *curr_bitmap;     // points to current frame
  116. short icurr_bitmap;        // index, this lets us set curr_bitmap easily
  117. short curr_bitmap_type;
  118. USHORT curr_bitmap_size;
  119.  
  120. BYTE change_mode;          // dead, stop, forward, back, ping-pong, etc.
  121. short change_delay;        // ticks between bitmaps
  122. ULONG next_change;         // tick at which we change frames
  123.  
  124. short d_pong;              // direction when ping-ponging
  125.  
  126. // x, y movement controls
  127. short x, y;
  128. short x_min, x_max;         // Bounding rectangle for movement - x
  129. short y_min, y_max;         // Bounding rectangle for movement - y
  130.  
  131. short dx, dy;             // Delta x, delta y.
  132. short prev_cx, prev_cy;   // visual center for previous bitmap
  133.                                                     // - used to adjust x, y when changing bitmaps
  134. short pixel_width, pixel_height;  // in pixels, handy to have it here instead of
  135.                                                                     // buried in bitmap
  136. short move_mode;          // what to do at limits, disappear, hold, bounce.
  137.  
  138. // Collision support: margin_left, right, etc. = margins to make the
  139. //                collision rectangle smaller than the outer corners.
  140. short collision;          // Collision detected
  141.  
  142. // Collision support, used for a smaller rectangle based on shape of
  143. //  bitmap, all are offsets from x,y.
  144. short collide_left, collide_right;
  145. short collide_top,  collide_bottom;
  146.  
  147. // clipping support
  148. short clip_left, clip_right;
  149. short clip_top, clip_bottom;
  150. short clipping;
  151. short erase_enabled;
  152.  
  153. short x_delay, y_delay;   // delay between moves
  154. ULONG next_x, next_y;     // tick at which next move happens
  155.  
  156. // scaling support
  157. BYTE is_scaled;  // 0/1
  158. short curr_width, curr_height;    // current width/height in pixels
  159. short w_min, w_max;               // min, max width in pixels
  160. short h_min, h_max;               // min, max height in pixels
  161.  
  162. short dw, dh;             // change in width/height
  163. short w_delay, h_delay;   // ticks between size changes
  164. ULONG next_w, next_h;     // tick at which next change ocurrs
  165.  
  166. short x_offs1, y_offs1;   // offsets used to start bullets, missiles,
  167. short x_offs2, y_offs2;   // attach objects, etc.
  168. short x_offs3, y_offs3;
  169. short x_offs4, y_offs4;
  170.  
  171. void far *user0;          // user defined
  172. void far *user2;
  173. void far *user3;
  174. void far *user4;
  175. }
  176. sprite_t;
  177.  
  178. typedef struct
  179.      {
  180.      short num_sprites;
  181.      short max_sprites;
  182.      BYTE  erase_enabled;
  183.      sprite_t far *sprites;    // list of sprite instances
  184.      }
  185. sprite_bank_t;
  186.  
  187.  
  188.  
  189. /*------------ Function Prototypes ---------------*/
  190.  
  191. short collidedWithObj( sprite_t far *s, short objLeft, short objRight,
  192.                        short objTop, short objBottom );
  193.  
  194. // Note: -1 for change_mode or move_mode sets them to defaults in header
  195. void start_scaled_sprite(sprite_t far *s, short change_mode, short move_mode,
  196.                                  short x, short y, short dx, short dy,
  197.                                  short init_xscale, short init_yscale, short dw, short dh);
  198. void start_sprite(sprite_t far *s, short change_mode, short move_mode,
  199.                         short x, short y, short dx, short dy);
  200.  
  201. void limit_sprite(sprite_t far *s);
  202. void move_sprite(sprite_t far *s, ULONG frozen_tick);
  203. void scale_sprite(sprite_t far *s, ULONG frozen_tick);
  204.  
  205. void draw_sprite(sprite_t far *s);
  206. void draw_sprite_offs(sprite_t far *s, short x_offs, short y_offs);
  207.  
  208. void change_bitmap(sprite_t far *s, ULONG frozen_tick);
  209. void set_bitmap(sprite_t far *s, short i_bitmap);
  210.  
  211. short add_sprite_instance(sprite_bank_t far *bank, sprite_header_t far *hd,
  212.                           short id,  short clip_left, short clip_right,
  213.                                      short clip_top, short clip_bottom,
  214.                           short x_min, short x_max, short y_min,
  215.                           short y_max, short erase);
  216.  
  217. short del_sprite_instance( sprite_bank_t far *bank, short id );
  218.  
  219. sprite_t far *get_sprite_instance(sprite_bank_t far *bank, short id);
  220.  
  221. BYTE far *init_spr_bmlist( sprite_header_t far *hd );
  222. void deinit_spr_bmlist( sprite_header_t far *hd );
  223.  
  224. #endif
  225. /* ------------------------------ EOF -------------------------------- */
  226.  
  227.